%% Figure 2: Brazil: Education Attainment Probabilities, by Parents and Locations
% Stacked Bar Graphs to Represent Transition Matrices


MM_rural = [0.520788559	0.405142243	0.059961185	0.012693247	0.001414766
            0.141884282	0.566184336	0.199386805	0.073203832	0.019340746
            0.085876597	0.26562248	0.243633627	0.25716385	0.147703446
            0.040306442	0.205222014	0.098186366	0.435803627	0.220481551
            0.0734167	0.136703868	0.185110484	0.298910851	0.305858097
            ];

MM_urban = [0.275809447	0.471739078	0.163380905	0.067928995	0.021141576
            0.039735719	0.336432048	0.269721028	0.215755261	0.138355944
            0.017377827	0.120315281	0.234417174	0.314118932	0.313770785
            0.007071892	0.066077328	0.126529997	0.341554249	0.458766534
            0.004369003	0.035446141	0.09384853	0.238116527	0.6282198
            ];

MM_favelaRJ =[0.344872308	0.436751269	0.192428306	0.024867076	0.00108104
            0.069349421	0.373601826	0.400443502	0.131997391	0.024607859
            0.08928339	0.26785017	0.410729625	0.214280136	0.017856678
            0	0.071428571	0.285714286	0.321428571	0.321428571
            0.090909091	0.136363636	0.272727273	0.227272727	0.272727273
            ];

MM_cityRJ =[0.158774294	0.411142899	0.300836188	0.099721379	0.02952524
            0.020913691	0.197578989	0.35113004	0.243807481	0.186569798
            0.010238449	0.085320412	0.286686533	0.331058122	0.286696483
            0	0.037973282	0.098111484	0.363924459	0.499990774
            0.003424589	0.010273767	0.08904431	0.253424589	0.643832744];


figure(1)
newcolors = [0 0 0
            0.2 0.2 0.2
            0.4 0.4 0.4
            0.7 0.7 0.7
            1 1 1];
gray=colororder(newcolors);
bar(MM_rural,'stacked');
ylim([0 1]);
title('Brazil, All Rural Locations','FontSize',12)
xlabel('parental years of schooling','FontSize',12)
ylabel('prob. children schooling attainment','FontSize',12)
legend( '0 ',' 1 to 4 ', '5 to 8','9 to 11 ',' 12 or +','Location','eastoutside','FontSize',12)
somenames={'0 ',' 1 to 4 ', '5 to 8','9 to 11 ',' 12 or +'};
set(gca,'xticklabel',somenames,'FontSize',12)
applyhatch(gcf,'x/.',gray);
axis tight
print -depsc IntergenerationalMatrix_Rural


figure(2)
newcolors = [0 0 0
            0.2 0.2 0.2
            0.4 0.4 0.4
            0.7 0.7 0.7
            1 1 1];
gray=colororder(newcolors);
bar(MM_favelaRJ,'stacked');
title('Rio de Janeiro, Poorer Locations','FontSize',12)
xlabel('parental years of schooling','FontSize',12)
ylabel('prob. children schooling attainment','FontSize',12)
legend( '0 ',' 1 to 4 ', '5 to 8','9 to 11 ',' 12 or +','Location','eastoutside','FontSize',12)
somenames={'0 ',' 1 to 4 ', '5 to 8','9 to 11 ',' 12 or +'};
set(gca,'xticklabel',somenames,'FontSize',12)
applyhatch(gcf,'x/.',gray);
axis tight
print -depsc IntergenerationalMatrix_RJpoorer



figure(3)
newcolors = [0 0 0
            0.2 0.2 0.2
            0.4 0.4 0.4
            0.7 0.7 0.7
            1 1 1];
gray=colororder(newcolors);
bar(MM_cityRJ,'stacked');
title('Rio de Janeiro, Richer Locations','FontSize',12)
xlabel('parental years of schooling','FontSize',12)
ylabel('prob. children schooling attainment','FontSize',12)
legend( '0 ',' 1 to 4 ', '5 to 8','9 to 11 ',' 12 or +','Location','eastoutside','FontSize',12)
somenames={'0 ',' 1 to 4 ', '5 to 8','9 to 11 ',' 12 or +'};
set(gca,'xticklabel',somenames,'FontSize',12)
applyhatch(gcf,'x/.',gray);
axis tight
print -depsc IntergenerationalMatrix_RJricher





